Write a C program to print pyramids and patterns using for loop || Program of Pyramids || C Programming
Write a C program to print pyramids and patterns using for loop
#include <stdio.h>
#include <conio.h>
#include <conio.h>
void main()
{
int i, j, rows, k = 0;
printf (" Enter a number to define the rows: \n");
scanf ("%d", &rows);
for ( i =1; i <= rows; i++)
{
for ( j = 1; j <= rows - i; j++)
{
printf (" ");
}
// use for loop where k is less than equal to (2 * i -1)
for ( k = 1; k <= ( 2 * i - 1); k++)
{
printf ("* "); // print the Star
}
printf ("\n");
}
getch();
Comments
Post a Comment